<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateWechaterTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 注意：不是所有的字段都能通过网页授权获取的
        // IP地址暂时只支持IPv4
        Schema::create('wechaters', function (Blueprint $table) {
            $table->increments('id');
            $table->boolean('subscribe')->default(false)->comment('是否关注公众号');
            $table->string('openid', 32)->unique()->comment('openid');
            $table->string('nickname')->nullable()->comment('微信呢称');
            $table->tinyInteger('sex')->nullable()->comment('性别：0未知，1男，2女');
            $table->string('city', 32)->nullable()->comment('城市');
            $table->string('country', 32)->nullable()->comment('国家');
            $table->string('province', 32)->nullable()->comment('省份');
            $table->string('language', 16)->nullable()->comment('语言');
            $table->string('headimgurl')->nullable()->comment('头像');
            $table->integer('subscribe_time')->nullable()->comment('最后一次关注时间戳');
            $table->string('unionid', 32)->nullable()->unique()->comment('unionid');
            $table->string('privilege')->nullable()->comment('微信特权信息，包含json数据');
            $table->boolean('has_userinfo')->default(false)->comment('是否已经获取到了用户详情');
            $table->timestamp('last_auth_info_time')->nullable()->comment('上一次授权获取详情时间戳');
            $table->string('scene', 32)->nullable()->comment('带参数二维码则会收到额外的场景代码');
            $table->integer('login_times')->default(0)->comment('总登陆次数');
            $table->bigInteger('created_ip')->nullable()->comment('注册时的IP');
            $table->bigInteger('last_login_ip')->nullable()->comment('最后一次登陆时的IP');
            $table->timestamp('last_login_time')->nullable()->comment('最后一次登陆的时间');
            $table->timestamps();
        });        
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('wechaters');
    }
}
